package com.example.MultiViewPage;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Fcy on 2015/11/10.
 */
public class MyAdapter extends PagerAdapter
{
	private List<String> imageUrls;

	public MyAdapter(List<String> imageUrls)
	{
		this.imageUrls = imageUrls;
	}

	@Override
	public int getCount()
	{
		return imageUrls.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object)
	{
		return (view == object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position)
	{
		View view = LayoutInflater.from(container.getContext())
		        .inflate(R.layout.item, container, false);
		TextView tv = (TextView) view.findViewById(R.id.tv);
		tv.setText(imageUrls.get(position));
		container.addView(view, position);
		return view;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object)
	{
		((ViewPager) container).removeView((View) object);
	}
}
